<?php

namespace app\Backend\controller;

use app\xt\Auth;
use think\Controller;
use think\Request;
use app\common\model\User;

class Login extends Controller
{
    public function index()
    {
        // 临时关闭当前模板的布局功能
        $this->view->engine->layout(false);
        return view('');
    }

    public function postLogin(Request $request)
    {
        $username = $request->post('username');
        $password = $request->post('password');

        if ($username == '' || $password == '') {
            $this->error('请填写完整数据！');
        }

        $password = md5($password);

        $auth = Auth::getInstance();

        $loginResult = $auth->login(['username' => $username, 'password' => $password]);
        if ($loginResult == false) {
            $this->error('登陆失败！');
        }
        $this->redirect('/admin');
    }

    public function logout()
    {
        $auth = Auth::getInstance();
        $auth->loginout();
        $this->redirect('/admin/login');
    }
}
